<template>
  <el-select v-bind="$attrs" v-on="$listeners" @change="change" clearable filterable>
    <el-option v-for="option in $attrs.options" :label="option[$attrs.config.optionKey]" :value="option[$attrs.config.optionValue]"/>
  </el-select>
</template>

<script>
export default {
  // watch: {
  //   '$attrs.options'(value) {
  //     console.log(value)
  //
  //   }
  // },
  methods: {
    change(value) {
      const selectedOptions = this.$attrs.options.filter(option => value == option[this.$attrs.config.optionValue])
      if (selectedOptions.length) {
        const selectedOption = selectedOptions[0]
        this.$emit('select', selectedOption)
      }
    }
  }
}
</script>

<style lang="scss" scoped>

</style>